// export interface IndexModelState {
//     bannerList: Array<any>;
// }

export interface IndexModelType {
    namespace: 'hero';
    state: any;
    reducers: {
        setProps: any,
        addSkin: any,
        clear: any,
        delSkins: any,
        addSkill: any,
        addRelation: any
    };
}

const IndexModel: IndexModelType = {
    namespace: 'hero',
    state: {
        // 英雄名称
        name: "",
        // 称号
        title: "",
        // 英雄定位
        cate: [],
        // 评分
        scores: {
            // 难度
            difficulty: "",
            // 技能
            skill: "",
            // 攻击
            attack: "",
            // 生存
            survive: ""
        },
        // 头像
        avatar: "",
        // 背景图
        banner: "",
        // 图文介绍
        photo: "",
        // 英雄皮肤  name   img
        skins: [],
        // 介绍视频
        shipin: {
            fan: "",
            submit: "",
            title: "",
            video: "",
            view: ""
        },
        // 使用技巧
        usageTips: "",
        // 对抗技巧
        battleTips: "",
        // 团战思路
        teamTips: "",
        // 顺风   equipment   tips
        downWind: {},
        // 逆风
        upWind: {},
        // 技能管理
        // 技能名称  name
        // 技能图标  icon
        // 冷却值  delay
        // 消耗  cost
        // 技能描述  desc
        // 小提示  tips
        skills: [],
        // 最佳搭档   desc   hero
        partners: [],
        // 被谁克制
        restrained: [],
        // 克制谁
        restraint: []
    },
    reducers: {
        setProps(state: any, action: any) {
            let newState = JSON.parse(JSON.stringify(state))
            // 设置评分属性
            if (action.scores) {
                newState.scores[action.prop] = action.val
            } else if (action.skins) {
                newState.skins[action.index][action.prop] = action.val
            } else if (action.shipin) {
                newState.shipin[action.prop] = action.val
            } else if (action.recommend) {
                newState[action.recommend][action.prop] = action.val
            } else if (action.skills) {
                console.log(newState[action.skills])
                newState[action.skills][action.index][action.action ? action.action : action.prop] = action.val
            } else {
                newState[action.prop] = action.val
            }
            return newState
        },
        // 清空皮肤
        clear(state: any, action: any) {
            let newState = JSON.parse(JSON.stringify(state))
            newState[action.action] = []
            return newState
        },
        // 添加皮肤
        addSkin(state: any) {
            let newState = JSON.parse(JSON.stringify(state))
            newState.skins.push({
                name: "",
                img: ""
            })
            return newState
        },
        // 删除皮肤  删除皮肤
        delSkins(state: any, action: any) {
            let newState = JSON.parse(JSON.stringify(state))
            newState[action.action].splice(action.index, 1)
            return newState
        },
        // 添加技能
        addSkill(state: any) {
            let newState = JSON.parse(JSON.stringify(state))
            newState.skills.push({
                name: "",
                icon: "",
                delay: "",
                cost: "",
                desc: "",
                tips: "",
            })
            return newState
        },
        // 添加英雄关系
        addRelation(state: any, action: any) {
            let newState = JSON.parse(JSON.stringify(state))
            newState[action.prop].push({
                desc: "",
                hero: ""
            })
            return newState
        }
    }
};

export default IndexModel;